import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author zyj
 * @date 2022年06月10日 16:44
 */
public class Client {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost",8080);
            OutputStream out = socket.getOutputStream();
            InputStream in = socket.getInputStream();

            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
            boolean flag = true;
            while (flag){
                System.out.print("请输入信息：") ;
                String str = input.readLine() ;	// 接收键盘的输入信息
                writer.write(str);
                writer.newLine();
                writer.flush();
                if("exit".equals(str)){
                    flag = false ;
                }else{
                    String echo = reader.readLine() ;	// 接收返回结果
                    System.out.println(echo) ;	// 输出回应信息
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
